package 递归;

import java.io.File;

public class a233 {
    static int ce = -1;
    public static void main(String[] args){
        String fs= "C:\\Users\\User\\JAVA\\01";
        function(fs);
    }
    public static void  function(String fs){
        ce++;
        File file = new File(fs);
        File[] fl =  file.listFiles();//获得文件夹内部的文件队列
        for (int i=0;i<fl.length;i++) {//遍历结构数组
            for(int ai=0;ai<ce;ai++){
                System.out.print("│");
            }
            if(i==fl.length-1)//整个文件的最后一个元素
            {
                if (new File(fl[i].toString()).isDirectory())
                {
                    System.out.print("└");
                    System.out.println(fl[i].toString().substring(fs.length()+1));
                    function(fl[i].toString());
                }else{
                    for(int ai=0;ai<ce;ai++){
                        System.out.print(" ");
                    }
                    System.out.println("└"+fl[i].toString().substring(fs.length()+1));
                }
                ce--;
                return;
            }
            else{
                //没到最后一个了
                if (new File(fl[i].toString()).isDirectory())
                {
                    System.out.print("├");
                    System.out.println(fl[i].toString().substring(fs.length()+1));
                    function(fl[i].toString());
                }else
                {
                    System.out.println("  └"+fl[i].toString().substring(fs.length()+1));
                }
            }
        }
        ce --;
        return;
    }

}
